// 节流
// 法1
// 设置一个事件戳
function debounce(fn, time = 2000) {
    let old = 0
    return function() {
        let newTime = new Date.now()
        if(newTime - old < time) {
            return
        }
        setTimeout(() => {
            fn()
        }, time)
        old = newTime
    }
}

// 法2
// 设置一个标志
function throttle(fn, delay) {
    let flag = true;
    return () => {
      if (!flag) return;
      flag = false;
      timer = setTimeout(() => {
        fn();
        flag = true;
      }, delay);
    };
  }


// 防抖
function replay(fn) {
    let tiemr
    let args = [...arguments].slice(1)
    return function() {
        if(tiemr) {
            clearTimeout(tiemr)
        }
        tiemr = setTimeout(() => {
            fn()
        }, 200)
    }
}
